home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / libs / knowhow4 / micro.cpp < prev    next >
C/C++ Source or Header  |  1994-10-10  |  4KB  |  143 lines

  1. #include "micro.h"
  2. #include "global.h"
  3. #include "icon.h"
  4.  
  5. extern loc icon_size(int icon_type);    // defined in icon.cpp
  6.  
  7. void draw(rect r, loc ic)
  8.     {
  9.     loc field = icon_size(1);        // microscope works with size of icon 1
  10.     rect work(r.origin.X + field.X + 50,
  11.           r.origin.Y,
  12.           r.origin.X + field.X * 6 + 50,
  13.           r.origin.Y + field.Y * 5);
  14.     loc pos = e.where();
  15.     if(!work.contains(pos))
  16.     return;
  17.  
  18.     int x_pos = (pos.X - work.origin.X) / 5;   // No of cell 5x5 pixels
  19.     int y_pos = (pos.Y - work.origin.Y) / 5;
  20.  
  21.     int color;
  22.     if(e.msstatus.buttonstate == MOUSELEFT)  // left - do it,
  23.     {
  24.     setfillstyle(SOLID_FILL, global_i[6]);
  25.     color = global_i[6];
  26.     }
  27.     else
  28.     {
  29.     setfillstyle(SOLID_FILL, global_i[7]);
  30.     color = global_i[7];
  31.     }
  32.     mouseHideCursor();
  33.     putpixel(ic.X + x_pos, ic.Y + y_pos, color);
  34.     bar(work.origin.X + x_pos * 5, work.origin.Y + y_pos * 5,
  35.     work.origin.X + (x_pos + 1) * 5, work.origin.Y + (y_pos + 1) * 5);
  36.     mouseShowCursor();
  37.     }
  38. //////////////////////////
  39. void reflect(loc from, loc to)
  40.     {
  41.     int color;
  42.     loc end = from + icon_size(1);
  43.     for(int i = from.X; i < end.X; i++)
  44.     for(int j = from.Y; j < end.Y; j++)
  45.         {
  46.         color = getpixel(i, j);
  47.         setfillstyle(SOLID_FILL, color);
  48.         bar(to.X + (i - from.X) * 5, to.Y + (j - from.Y) * 5,
  49.         to.X + (i - from.X + 1) * 5, to.Y + (j - from.Y + 1) * 5);
  50.         }
  51.     }
  52. /////////////////////////
  53. Micro::Micro(rect coord)
  54.     :Window(coord)
  55.     {
  56.     }
  57. /////////////////////////
  58. void Micro::show()
  59.     {
  60.     Window::show();
  61.     mouseHideCursor();
  62.     loc field = icon_size(1);            // microscope works with size of icon 1
  63.     rect r = user_screen();
  64.  
  65.     Carcase c;
  66.     rect work(r.origin.X + field.X + 50,
  67.           r.origin.Y,
  68.           r.origin.X + field.X * 6 + 50,
  69.           r.origin.Y + field.Y * 5);
  70.  
  71.     setfillstyle(SOLID_FILL, pColorSet->colors.ATTR_COLOR);
  72.     c.show(SHOW_BORDER, rect(work.origin - 6, work.corner + 6));
  73.  
  74.     void* image;
  75.     if(image = get_image("copy.res", 1))
  76.     putimage(r.origin + 6, image);
  77.     delete image;
  78.  
  79.     c.show(BUTTON_BORDER, rect(r.origin.X + 2, r.origin.Y + 2,
  80.         r.origin.X + field.X + 10,
  81.         r.origin.Y + field.Y + 10));
  82.  
  83.     reflect(r.origin + 6, work.origin);
  84.     mouseShowCursor();
  85.     }
  86. ///////////////////////////////
  87. void Micro::exe(int act)
  88.     {
  89.     e.what = act ? KEYEVENT : NOEVENT;
  90.     switch(act)
  91.     {
  92.     case AC_CANCEL: e.key = (isRet(RET_REMOVE))
  93.         ? EVENT_ALT_F3 : EVENT_ESC;
  94.         break;
  95.     case AC_OK:     e.key = EVENT_F2; break;
  96.     }
  97.     rect r = user_screen();
  98.     mouseHideCursor();
  99.     if(!act)
  100.     hilite();
  101.     mouseShowCursor();
  102.  
  103.     while(1)
  104.     {
  105.     if(!act)
  106.         get_event();
  107.     if(e.what == KEYEVENT)
  108.         switch(e.key)
  109.         {
  110.         case EVENT_F1: return;
  111.  
  112.         case EVENT_ESC: global_num = 0;  // don't save
  113.             global_i[0] = AC_NULL;
  114.             e.what = KEYEVENT;
  115.             e.key = EVENT_ESC;
  116.             return;
  117.         case EVENT_F2:
  118.         case EVENT_RETURN:
  119.             unhilite(); global_num = 1;
  120.                     mouseHideCursor();
  121.             global_i[0] = action_type;
  122.             e.what = KEYEVENT;
  123.             e.key = EVENT_RETURN;
  124.             unlink("copy.res");
  125.             save_image("copy.res", user_screen().origin + 6, 1);
  126.                     mouseShowCursor();
  127.             return;
  128.         }
  129.     else
  130.         {
  131.         if(!mouse_in(loc(e.where())))
  132.         {
  133.         unhilite();
  134.         global_num = 0; global_i[0] = AC_NULL;
  135.         return;
  136.         }   // outside of menu box
  137.         else
  138.         draw(r, user_screen().origin + 6);
  139.         }
  140.     }
  141.     }
  142. //////////////////////////
  143.